package jfinalUtil;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

import tripController.AdminController;
import tripController.TripController;
import tripController.UserController;
import tripModel.Admin;
import tripModel.City;
import tripModel.Lcomment;
import tripModel.Limg;
import tripModel.Location;
import tripModel.Ncomment;
import tripModel.Nimg;
import tripModel.Note;
import tripModel.Total;
import tripModel.User;

public class MyJfinla extends JFinalConfig {

	@Override
	public void configConstant(Constants arg0) {
		arg0.setDevMode(true);// 开发者模式
		arg0.setViewType(ViewType.JSP);// 设置模板为jsp

	}

	@Override
	public void configEngine(Engine arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configInterceptor(Interceptors arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configPlugin(Plugins arg0) {
		super.loadPropertyFile("configuration.properties");
		DruidPlugin dp = new DruidPlugin(getProperty("url"), getProperty("user"), getProperty("password"));
		RedisPlugin rp = new RedisPlugin("myredis", getProperty("cacheurl"));
		arg0.add(dp);
		arg0.add(rp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		arg0.add(arp);
		arp.addMapping("admin", "aID", Admin.class);
		arp.addMapping("user", "uID", User.class);
		arp.addMapping("city", City.class);
		arp.addMapping("lcomment", "lcID", Lcomment.class);
		arp.addMapping("limg", "liID", Limg.class);
		arp.addMapping("location", "lID", Location.class);
		arp.addMapping("ncomment", "ncID", Ncomment.class);
		arp.addMapping("nimg", "niID", Nimg.class);
		arp.addMapping("note", "nID", Note.class);
		arp.addMapping("total", "tID", Total.class);
	}

	@Override
	public void configRoute(Routes arg0) {
		// arg0.setBaseViewPath("/WEB-INF/jsp/");
		arg0.add("/admin", AdminController.class);
		arg0.add("/", TripController.class, "/WEB-INF/jsp/");
		arg0.add("/user", UserController.class, "/WEB-INF/jsp/");
	}

}
